//
//  DiscoverSearchView.swift
//  新浪微博
//
//  Created by seteny on 16/7/12.
//  Copyright © 2016年 seteny. All rights reserved.
//

import UIKit

class DiscoverSearchView: UIView,UITextFieldDelegate {

    
    @IBOutlet weak var cancelButton: UIButton!
    
    @IBOutlet weak var textFieldConstraint: NSLayoutConstraint!
    
    @IBOutlet weak var textField: UITextField!
    
    
    //加载xib 
    class func searchView() -> DiscoverSearchView {
        
        
        return UINib(nibName: "DiscoverSearchView", bundle: nil).instantiateWithOwner(nil, options: nil).last! as! DiscoverSearchView
        
        
    }
    
    
    @IBAction func cancelButtonAction(sender: AnyObject) {
      
        //取消第一响应者
        textField.resignFirstResponder()
        textFieldConstraint.constant = 0
        
        UIView.animateWithDuration(0.25) { () -> Void in
            self.layoutIfNeeded()
        }
    }
    
    
    // MARK: -- UITextFieldDelegate  代理
    func textFieldDidBeginEditing(textField: UITextField) {
        
        textFieldConstraint.constant = cancelButton.width
        
        UIView.animateWithDuration(0.25) { () -> Void in
            self.layoutIfNeeded()
        }
        
    }
    
}
